
#include <iostream>
#include <cuda.h>
#include <cuda_runtime.h>

#include "static.h"
#include <cstdio>

result_type __device__ static_func(int x)
{
#ifdef __CUDA_ARCH__
#include "static_contents.h"
#endif
}


static
__global__
void LaunchKernel(result_type& r, int x)
{
  printf("LaunchKernel");
  //call static_func which is a method that is defined in the
  //static library that is always out of date
  r = static_func(x);
}

int main(int argc, char **argv)
{
  int x = 42;
  result_type r;
  LaunchKernel <<<1,1>>> (r,x);
  if(cudaSuccess != cudaGetLastError())
    {
    std::cout << "Failed to launch the kernel" << std::endl;
    return 1;
    }
  std::cout << "this executable launches a cuda kernel that will invoke" << std::endl;
  std::cout << "a kernel whose definition should come from another file " << std::endl;
  std::cout << "which cmake always considers to be out of date" << std::endl;
  std::cout << "result: " << r.sum << std::endl;

  return 0;
}